package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Children;
import org.hxyjs.entity.Children;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ChildrenService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/childrenController")
public class ChildrenController {
	@Resource
	ChildrenService childrenService;
	@RequestMapping("/getAllChildren")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Children> getAllChildren() throws Exception {
    	System.out.println("查询全部儿童");
		return childrenService.getAllChildrens();
    }

	@RequestMapping("/deleteChildrenByCno/{cno}")
	@ResponseBody
    public DTO<Children> deleteChildrenByCno(@PathVariable("cno") String cno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(cno+"删除儿童");
    	return childrenService.deleteChildrenByCno(cno);
    }

	@RequestMapping("/updateChildrenByCno")
	@ResponseBody
	public DTO<Children> updateChildrenByCno(@RequestBody Children children) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改儿童");
		return childrenService.updateChildrenByCno(children);
	}


	@RequestMapping("/addChildren")
	@ResponseBody
	public DTO<Children> addChildren(@RequestBody Children children) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加儿童");
		System.out.println(children);
 		return childrenService.addChildren(children);
	}
	@RequestMapping("/getChildrenByPage")
	@ResponseBody
	public DTO<Children> getChildrenByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页儿童");
		return childrenService.getChildrenByPage(pageInfo);
	}

}